using System;
using System.Collections.Generic;
using System.Drawing.Design;
using System.Text;
using System.Windows.Forms.Design;

namespace Workflows.Components
{
    /// <summary></summary>
    public class GlobalVariableTypeEditor:UITypeEditor 
    {
        private IWindowsFormsEditorService _Service;

        /// <summary></summary>
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if(context !=null && context.Instance !=null && provider !=null)
            {
                this._Service = provider.GetService(typeof (IWindowsFormsEditorService)) as IWindowsFormsEditorService;
                if(this._Service !=null)
                {
                    Dictionary<string, object> globalVars = (Dictionary<string, object>) value;
                    GlobalVariableEditorForm.Edit(ref globalVars);
                    value = globalVars;
                }
            }
            return value;
        }

        public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            if(context !=null && context.Instance !=null)
            {
                return UITypeEditorEditStyle.Modal;
            }
            return base.GetEditStyle(context);
        }
    }
}
